﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Graphics;
using Terraria.Localization;
using Terraria.UI;

namespace Terraria.GameContent.UI.Elements
{
	// Token: 0x020003FC RID: 1020
	public class UIText : UIElement
	{
		// Token: 0x1700028B RID: 651
		// (get) Token: 0x060023D3 RID: 9171 RVA: 0x00019522 File Offset: 0x00017722
		public string Text
		{
			get
			{
				return this._text.ToString();
			}
		}

		// Token: 0x1700028C RID: 652
		// (get) Token: 0x060023D4 RID: 9172 RVA: 0x0001952F File Offset: 0x0001772F
		// (set) Token: 0x060023D5 RID: 9173 RVA: 0x00019537 File Offset: 0x00017737
		public Color TextColor
		{
			get
			{
				return this._color;
			}
			set
			{
				this._color = value;
			}
		}

		// Token: 0x060023D6 RID: 9174 RVA: 0x00019540 File Offset: 0x00017740
		public UIText(string text, float textScale = 1f, bool large = false)
		{
			this.InternalSetText(text, textScale, large);
		}

		// Token: 0x060023D7 RID: 9175 RVA: 0x00019540 File Offset: 0x00017740
		public UIText(LocalizedText text, float textScale = 1f, bool large = false)
		{
			this.InternalSetText(text, textScale, large);
		}

		// Token: 0x060023D8 RID: 9176 RVA: 0x0001957D File Offset: 0x0001777D
		public override void Recalculate()
		{
			this.InternalSetText(this._text, this._textScale, this._isLarge);
			base.Recalculate();
		}

		// Token: 0x060023D9 RID: 9177 RVA: 0x0001959D File Offset: 0x0001779D
		public void SetText(string text)
		{
			this.InternalSetText(text, this._textScale, this._isLarge);
		}

		// Token: 0x060023DA RID: 9178 RVA: 0x0001959D File Offset: 0x0001779D
		public void SetText(LocalizedText text)
		{
			this.InternalSetText(text, this._textScale, this._isLarge);
		}

		// Token: 0x060023DB RID: 9179 RVA: 0x000195B2 File Offset: 0x000177B2
		public void SetText(string text, float textScale, bool large)
		{
			this.InternalSetText(text, textScale, large);
		}

		// Token: 0x060023DC RID: 9180 RVA: 0x000195B2 File Offset: 0x000177B2
		public void SetText(LocalizedText text, float textScale, bool large)
		{
			this.InternalSetText(text, textScale, large);
		}

		// Token: 0x060023DD RID: 9181 RVA: 0x0047AA58 File Offset: 0x00478C58
		private void InternalSetText(object text, float textScale, bool large)
		{
			DynamicSpriteFont dynamicSpriteFont = large ? Main.fontDeathText : Main.fontMouseText;
			Vector2 vector = new Vector2(dynamicSpriteFont.MeasureString(text.ToString()).X, large ? 32f : 16f) * textScale;
			this._text = text;
			this._textScale = textScale;
			this._textSize = vector;
			this._isLarge = large;
			this.MinWidth.Set(vector.X + this.PaddingLeft + this.PaddingRight, 0f);
			this.MinHeight.Set(vector.Y + this.PaddingTop + this.PaddingBottom, 0f);
		}

		// Token: 0x060023DE RID: 9182 RVA: 0x0047AB08 File Offset: 0x00478D08
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			base.DrawSelf(spriteBatch);
			CalculatedStyle innerDimensions = base.GetInnerDimensions();
			Vector2 pos = innerDimensions.Position();
			if (this._isLarge)
			{
				pos.Y -= 10f * this._textScale;
			}
			else
			{
				pos.Y -= 2f * this._textScale;
			}
			pos.X += (innerDimensions.Width - this._textSize.X) * 0.5f;
			if (this._isLarge)
			{
				Utils.DrawBorderStringBig(spriteBatch, this.Text, pos, this._color, this._textScale, 0f, 0f, -1);
				return;
			}
			Utils.DrawBorderString(spriteBatch, this.Text, pos, this._color, this._textScale, 0f, 0f, -1);
		}

		// Token: 0x04003FFE RID: 16382
		private object _text = "";

		// Token: 0x04003FFF RID: 16383
		private float _textScale = 1f;

		// Token: 0x04004000 RID: 16384
		private Vector2 _textSize = Vector2.Zero;

		// Token: 0x04004001 RID: 16385
		private bool _isLarge;

		// Token: 0x04004002 RID: 16386
		private Color _color = Color.White;
	}
}
